const path = require('path');
const webpack = require("webpack");
const CompressionPlugin = require("compression-webpack-plugin");
const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i;

function resolve(dir) {
	return path.join(__dirname, dir);
}
const port = 8080; // 端口配置

module.exports = {
	transpileDependencies: ["marked"],
	runtimeCompiler: true,
	productionSourceMap: false,
	lintOnSave: false,
	devServer: {
		hot: true,
		open: true,
		port: port,
		overlay: {
			warnings: false,
			errors: false
		},
		disableHostCheck: true
	},
	configureWebpack: {
		name: process.env.VUE_APP_TITLE,
		// provide the app's title in webpack's name field, so that
		// it can be accessed in index.html to inject the correct title.
			plugins: [
				new webpack.IgnorePlugin(/cptable/)
			],
			externals: [{
				"./cptable": "var cptable"
			}],
		devtool: 'source-map',
		resolve: {
			alias: {
			'@': resolve('src'),
			}
		},
	},
	publicPath: process.env.VUE_APP_BASE_PATH,
	outputDir: 'wheel',
	chainWebpack(config) {
	// set svg-sprite-loader
		if (process.env.NODE_ENV !== "development") {
			config.plugin("compressionPlugin")
				.use(new CompressionPlugin({
					filename: "[path].gz[query]",
					algorithm: "gzip",
					test: productionGzipExtensions,
					threshold: 10240,
					minRatio: 0.5,
					deleteOriginalAssets: true
				}));
		}
	}
};
